package co.sanduche.teach;

import java.util.List;

import co.sanduche.models.Enums;
import co.sanduche.teach.gallery.AndroidStudent;
import co.sanduche.teach.gallery.PostDBHelper;
import co.sanduche.teach.gallery.StudentsDBOpenHelper;
import co.sanduche.teach.service.AndroidPost;
import co.sanduche.teach.service.PostTask;
import co.sanduche.teach.service.TaskExecutorService;
import co.sanduche.vos.Tuple;

public class PostPresenter {

	private PostActivity postActivity;
	private long idClass;
	private List<AndroidStudent> students;
	private PostDBHelper postDBHelper;

	@SuppressWarnings("unchecked")
	public PostPresenter(PostActivity postActivity) {
		this.postActivity = postActivity;
		this.idClass = TeachApp.getInstance().getGlobalSharedPreferences()
				.getLong("idClass", -1);
		this.students = new StudentsDBOpenHelper(postActivity)
				.loadAllData(idClass);
		postDBHelper = new PostDBHelper(postActivity);

	}

	public void init() {
		postActivity.setStudentsList(students);
	}

	public void postPost(List<Tuple<Enums.ChannelType, Long>> channels,
			List<Long> photos) {
		AndroidPost ap = postDBHelper.insert(photos, channels);
		TaskExecutorService.newTask(postActivity, PostTask.class, ap.id);
	}

}
